package kamikaze.service.member;

import java.util.List;

import kamikaze.entity.Order;
import kamikaze.support.HttpMethod;
import kamikaze.support.Service;
import kamikaze.support.ServiceConfig;
import kamikaze.support.ServiceContext;

@ServiceConfig(path = "user/trans", method = HttpMethod.GET)
public class ViewTransactionHistoryPage implements Service {

	@Override
	public String serve(ServiceContext ctx) throws Exception {
		ctx.getUserSession().ensureLoginAsUser();

		List<Order> list = ctx.getEntityManager()
				.createQuery("select t from Order t where t.userId = :userId order by t.date desc")
				.setParameter("userId", ctx.getUserSession().asUser().getId())
				.getResultList();

		for (Order order : list) {
			order.getItemList().size();
		}

		ctx.getRequest().setAttribute("orderList", list);

		return "user/transaction_history";
	}
}
